let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: '',
  },
  toRegister(){
    wx.navigateTo({
      url: '/pages/my/register/register'
    })
  },
  UserLogin(e) {
    const { account, password } = e.detail.value;
    if (!account || !password) {
      wx.showToast({
        title: '请输入账号和密码',
        icon: 'none',
        duration:1000
      });
      return;
    }

    wx.request({
      url: this.data.url + 'user',
      data: e.detail.value,
      method: "GET",
      success: (resp) => {
        if (resp.data.code === 200) {
          wx.setStorageSync('user', resp.data.data);
        const userData = resp.data.data;
        app.globalData.userInfo = userData;
        wx.setStorageSync('userInfo', userData);
          wx.showToast({
            title: '登录成功',
            icon: 'success',
          });
          setTimeout(() => {
            wx.switchTab({
              url: '/pages/my/my'
            });
          }, 2000);
        } else {
          wx.showToast({
            title: resp.data.msg || '账号或密码错误',
            icon: 'error',
            duration:1000
          });
        }
      },
      fail: () => {
        wx.showToast({
          title: '网络请求失败',
          icon: 'error'
        });
      }
    });
  },

  toRegisterPage() {
    wx.navigateTo({
      url: '/pages/register/register'
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      url: app.globalData.url
    });
  },

  // 其他生命周期函数保持不变...
})